define(['jquery', 'bootstrap', 'backend', 'form', 'table','layui'], function ($, undefined, Backend, Form, Table) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'product/index/index',
                    add_url: 'product/index/add',
                    edit_url: 'product/index/edit',
                    del_url: 'product/index/del',
                    multi_url: 'product/index/multi',
                    import_url: 'product/index/import', //导入接口链接
                    table: 'index'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                showExport:false,
                pageSize:15,
                columns: [
                    [
                        {field: 'state', checkbox: true},
                        {field: 'id', title: __('ID'),operate: false,sortable: true},
                        {field: 'url', title: '预览', events: Table.api.events.image, formatter: Table.api.formatter.image,operate: false},
                        {field: 'name', title: '名称', sortable: false},
                        {field: 'spec', title: '规格', sortable: false},
                        // {field: 'width', title: '宽度', sortable: true,operate: false},
                        // {field: 'height', title: '高度', sortable: true,operate: false},
                        {field: 'size', title: '尺寸', sortable: false,operate: false,
                            formatter: function (value) {
                            return value.toString().substr(0,80);
                            }
                        },
                        {field: 'status', title: __("Status"), searchList: {"1":"正常","-1":"异常"}, custom:{"1":"green","-1":"red"},formatter: Table.api.formatter.status},

                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            formatter: Table.api.formatter.datetime,
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            sortable: true,
                            width: 150
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ],
            });



            // 为表格绑定事件
            Table.api.bindevent(table);

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        pdf: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },

        }

    };
    return Controller;
});
